$(document).ready(function() {

var plist=[];
$('#awplus_content table:eq(0) tr:not(tr:first, tr:last) a').each(function() {
  plist.push($(this).attr('href').match(/([0-9]+)$/)[1] +':'+$(this).text());
});

if (!$.cookie('ap_planetlist')) {
  for (i in plist) {
    t = plist[i].split(':');
    $('#planets').addmenu(t[1], '/0/Planets/Detail.php/?i='+t[0]);
  }
}
$.cookie('ap_planetlist', plist.join('|'), {expires: 1, path: '/'});

// Getting Growth percents.
var gr_pr = $('#awplus_content table tr:last td:first').text();
var growth = gr_pr.match(/Growth ([-+]\d+)%/);
var productions = gr_pr.match(/Production ([-+]\d+)%/);

if (!growth) growth = '+0'; else growth = growth[1];
if (!productions) productions = '+0'; else productions = productions[1];

// Changing Production Points header to Prod. Pts.
$('#awplus_content table tr:first td:eq(3) a').text('Prod. Pts.');

growth = (parseInt(growth)/100)+1;
productions = (parseInt(productions)/100)+1;

var levels = [0, 21, 57, 111, 183, 273, 381, 507, 651, 813, 993, 1191, 1407, 
              1641, 1893, 2163, 2451, 2757, 3081, 3423, 3783, 4161, 4557, 
              4971, 5403, 5853, 6321, 3807, 7311];

var per_hour_tt = 0;
// All table rows
$('#awplus_content table tr:not(:first):not(:last)').each(function() {
  var lvl = parseInt($('td:eq(1)', this).text());
  var perc = $('td:eq(2) img:eq(0)', this).width();
  var hour = parseInt($('td:eq(3)', this).text());
  var per_hour = Math.round(hour*growth);
  var rmn = Math.round((levels[lvl] - ((perc * levels[lvl]) / 100)) / per_hour);
  
  $('td:eq(3)', this).append(' <sup style="font-size:8px; color: #80b0b0;">(+'+per_hour+') / '+rmn+'h</sup>');
  
  hour = parseInt($('td:eq(5)', this).text());
  per_hour = Math.round(hour*productions);
  per_hour_tt += per_hour;
  $('td:eq(5)', this).append(' <sup style="font-size:8px; color: #80b0b0;">(+'+per_hour+')</sup>');
});

$('#awplus_content table tr:last td:last').append(' <sup style="font-size:8px; color: #80b0b0;">(+'+per_hour_tt+')</sup>');

});
